package com.jic.product.service.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.product.mapper.FileMapper;
import com.jic.product.model.entity.File;
import com.jic.product.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公共文件表
 * @author : 
 * @email : 
 * @since : 2020-02-10 05:49:32
 * @version : v1.0.0
 */
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileMapper fileMapper;

    @Override
    public long insert(File file) {
        long flag = fileMapper.insert(file);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return fileMapper.delete(id);
    }

    @Override
    public long update(File file) {
        return fileMapper.update(file);
    }

    @Override
    public File queryByPrimaryKey(Long id){
        return fileMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<File> query(File file){
        return fileMapper.query(file);
    }

    @Override
    public PageResult<File> queryPage(File file, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<File> list = fileMapper.queryPage(startIndex, pageQuery.getLimit(), file);
        long count = fileMapper.queryPageCount(file);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}